<!DOCTYPE HTML>
<html>
<head>
<include file="public/header" />
<title>管理员添加</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员姓名：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="{$user.username}" placeholder="请填写管理员用户名" id="username" name="username">
		</div>
	</div>
	<if condition="!isset($user.id)">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$user.userpwd}" placeholder="请填写管理员用密码" id="userpwd" name="userpwd">
			</div>
		</div>
	</if>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机号：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="{$user.tel}" placeholder="请填写管理员身份证号" id="tel" name="tel">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="{$user.email}" placeholder="请填写管理员邮箱" id="email" name="email">
		</div>
	</div>
	
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">选择角色组：</label>
		<div class="formControls col-xs-8 col-sm-9 skin-minimal">
			<volist name="role" id="v">
				<div class="check-box">
					<input <if condition="in_array($v['id'],$roleuser)">checked</if> type="checkbox" id="role_{$v.id}" name="role[]" value="{$v.id}">
					<label for="role_{$v.id}">{$v.title}</label>
				</div>
			</volist>
		</div>
	</div>
	
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否启用：</label>
		<div class="formControls col-xs-8 col-sm-9 skin-minimal">
			<div class="radio-box">
				<input value="1" name="status" type="radio" id="status-1" checked>
				<label for="status-1">启用</label>
			</div>
			<div class="radio-box">
				<input value="0" name="status" type="radio" <if condition="$user['status'] === 0">checked</if> id="status-2">
				<label for="status-2">禁用</label>
			</div>
		</div>
	</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
	<input type="hidden" name="id" value="{$user.id}" />
	</form>
</article>

<include file="public/footer" />

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-add").validate({
		rules:{
			name:{
				required:true,
			},
			userpwd:{
				required:true,
			},
			tel:{
				required:true,
			},
			email:{
				required:true,
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "{:url('User/adduser')}" ,
				success: function(data){
					if(data.error=="success"){
						layer.msg('操作成功!',{icon:6,time:1000});
						setTimeout(function(){
							parent.location.replace(parent.location.href)
						},1500);
					}else{
						layer.msg(data.error,{icon:5,time:2000});
					}
				},
                error: function(err){
                	document.write(JSON.stringify(err));
					layer.msg('操作失败！',{icon:5,time:2000});
				}
			});
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>